package per.dg.tencent.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import java.util.ArrayList;
import java.util.List;

import per.dg.tencent.R;

public class BannerViewPagerAdapter extends PagerAdapter {

    private static final String TAG = "BannerViewPagerAdapter";

    View view;

    List mList;

    List<View> list;

    Context mContext;

    public BannerViewPagerAdapter(Context mContext, List mList){
        this.mList = mList;
        this.mContext = mContext;
        list = new ArrayList<>();
        for(int i = 0; i < mList.size(); i++){
            list.add(LayoutInflater.from(mContext).inflate(R.layout.item_vp_banner, null));
        }
    }

    @Override
    public int getCount() {
        Log.e(TAG, "getCount: "+mList.size() );
        return mList == null ? 0 : mList.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView((View) object);
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        View view = list.get(position);
        ((TextView)view.findViewById(R.id.app_tv_banner)).setText("第"+position+"ge");
        container.addView(view);
        return view;
    }
}
